package cn.yunhe.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.yunhe.biz.AdminBiz;
import cn.yunhe.model.Admin;

public class LoginServlet extends HttpServlet{
	
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name=request.getParameter("username");	
		String pwd=request.getParameter("password");
		
		AdminBiz adminBiz=new AdminBiz();
		Admin admin=adminBiz.adminLogin(name, pwd);
		
		if (admin!=null) {
			HttpSession session=request.getSession();
			session.setAttribute("admin", admin);
			request.getRequestDispatcher("index.jsp").forward(request, response);
			
		}
		
	}
	
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
